package com.yoda.mall.mysql.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.mall.api.AttributeApi;
import com.yoda.mall.model.entity.pms.ProductAttribute;
import com.yoda.mall.mysql.mapper.ProductAttributeMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author wangjia
 * @date 2022/12/17
 * @Description
 */
@DubboService
public class AttributeApiImpl implements AttributeApi {

    @Autowired
    private ProductAttributeMapper productAttributeMapper;

    //获得所有商品属性
    @Override
    public List<ProductAttribute> getAllattribute() {
        return productAttributeMapper.selectList(new LambdaQueryWrapper<>());
    }

    //添加商品属性
    @Override
    public void create(ProductAttribute attribute) {
        productAttributeMapper.insert(attribute);
    }

    //批量删除
    @Override
    public void deleteIds(List<Integer> ids) {
       productAttributeMapper.deleteBatchIds(ids);
    }

    //查询单个
    @Override
    public ProductAttribute findOne(Long id) {
        return productAttributeMapper.selectById(id);
    }

    //根据商品分类id获取商品属性及属性分类
    @Override
    public List<ProductAttribute> findPage(Long cid, Integer type, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<ProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductAttribute::getProductAttributeCategoryId, cid);
        queryWrapper.eq(ProductAttribute::getType, type);
        Page<ProductAttribute> page = new Page<>();
        return productAttributeMapper.selectPage(page,queryWrapper).getRecords();
    }
}
